﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DomainModel.Abstract;
using DomainModel.Entities;
using NHibernate;
using NHibernate.Criterion;

namespace DomainModel.Concrete
{
    public class RatesRepository : IRatesRepository
    {
        public void Save(Rate item)
        {
            ISession session = SessionManager.CurrentSession;
            session.BeginTransaction();
            session.Save(item);
            session.Transaction.Commit();
        }

        public Rate GetByEventIDAndUserID(int eventID, int userID)
        {
            ICriteria criteria = SessionManager.CurrentSession.CreateCriteria(typeof(Rate));
            return criteria.List<Rate>().Where(x => x.EventID == eventID).Where(x => x.UserID == userID).FirstOrDefault();
        }
         

        public void DeleteByEventIDAndUserID(Rate rateObject)
        {
            SessionManager.CurrentSession.Delete(rateObject);
           
        }
    }
}
